﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace MongoServices
{
	/// <summary>
	/// Indicates that the <see cref="MongoCollectionNameAttribute"/> was not applied to the model class.
	/// </summary>
	[Serializable]
	public class MongoCollectionNameMissingException : ApplicationException
	{
		#region Private Constructors
		/// <summary>
		/// Constructs the <see cref="MongoCollectionNameMissingException"/>.
		/// </summary>
		private MongoCollectionNameMissingException()
		{
		}
		#endregion

		#region Public Constructors
		/// <summary>
		/// Construsts the <see cref="MongoCollectionNameMissingException"/> based on the <c>mongoServicesModelType</c> parameter.
		/// </summary>
		/// <param name="mongoServicesModelType">The type of the model class.</param>
		public MongoCollectionNameMissingException(Type mongoServicesModelType)
			: base(MongoCollectionNameMissingException.FormatMessage(mongoServicesModelType))
		{
		}

		/// <summary>
		/// Construsts the <see cref="MongoCollectionNameMissingException"/> based on the <c>mongoServicesModelType</c> and the <c>innerException</c> parameters.
		/// </summary>
		/// <param name="mongoServicesModelType">The type of the model class.</param>
		/// <param name="innerException">The inner <c>Exception</c> to be included.</param>
		public MongoCollectionNameMissingException(Type mongoServicesModelType, Exception innerException)
			: base(MongoCollectionNameMissingException.FormatMessage(mongoServicesModelType), innerException)
		{
		}
		#endregion

		#region Protected Constructors
		/// <summary>
		/// Construsts the <see cref="MongoCollectionNameMissingException"/> based on the <c>info</c> and the <c>context</c> parameters.
		/// </summary>
		/// <param name="info">The serialization inforamtion.</param>
		/// <param name="context">The streaming context.</param>
		protected MongoCollectionNameMissingException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
		}
		#endregion

		#region Protected Static Methods
		/// <summary>
		/// Formats the message for the <see cref="MongoCollectionNameMissingException"/>.
		/// </summary>
		/// <param name="mongoServicesModelType">The type of the model class.</param>
		/// <returns>The formatted message string for the <see cref="MongoCollectionNameMissingException"/>.</returns>
		protected static string FormatMessage(Type mongoServicesModelType)
		{
			return "The " + mongoServicesModelType.FullName + " model does not specify the MongoCollectionNameAttribute";
		}
		#endregion
	}
}
